/*
 * Student Name: Seyed Saeed Ghiassy
 * Student ID  : 05994390
 * Supervisor  : Dr.Fakas
 * Project Name: Peer-to-Peer File Sharing Application Using JXTA technology
 * Unit Name   : Final Year Project
 * Unit Code   : 63CP3261
 * DeadLine    : 21-April-2008
 * University  : Manchester Metropolitan University
 * E-mail      : seyed.ghiassy@student.mmu.ac.uk
 * Softwares   : JXTA Version 2.4.1, JDK Version 1.6.0_05, NetBeans IDE 5.5
 */
package myPackage;

import java.awt.Component;
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
//import jxta Library
import net.jxta.share.ContentAdvertisement;

//this is Main Frame and it handles the Application start up and also initialisation of all
//object that are needed in out program
public class frmMain extends javax.swing.JFrame 
{
    //Defining Class Variables
    private final ImageIcon mp3Icon = new ImageIcon(getClass().getResource("/myPackage/myIcons/16x16/mp3Icon.png"));
    private final ImageIcon VideoIcon = new ImageIcon(getClass().getResource("/myPackage/myIcons/16x16/videoIcon.png"));
    private final ImageIcon OthersIcon = new ImageIcon(getClass().getResource("/myPackage/myIcons/16x16/otherfilesIcon.png"));
    
    static String Path = null;
    //Original check sum which will be taken from Content Advertisement
    //to make sure download is not corrupted
    static String OriginalCheckSum = "unknown";
    static String myFileName=null;
    
    //Classes that needed to launch into jxta, share contenets through JXTA network,
    //Search for content, Download content, Chat services and Peers Listing in Group
    static StartJXTA connection = null;
    static ChatInput chatIn = null;
    static ChatOutput chatOut=null;
    static PeersListing peersList = null;
    static SaEeDSharing launchSharing =null;
    static SearchFile startSearch =null;
    static DownloadFile download = null;
    static CheckSumCalc myCheckSum = new CheckSumCalc();
    
    static ContentAdvertisement [] contentAdv = null;
    
    public frmMain() //Main Frame Constructor 
    {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        AboutMe = new javax.swing.JDialog();
        jPanel7 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jScrollPane6 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jSeparator7 = new javax.swing.JSeparator();
        jScrollPane7 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        btnAccept = new javax.swing.JButton();
        btnExit = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtLog = new javax.swing.JTextArea();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtFilename = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        mySearchTable = new javax.swing.JTable();
        jSeparator3 = new javax.swing.JSeparator();
        btnSearch = new javax.swing.JButton();
        btnStop = new javax.swing.JButton();
        btnDownload = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        mySharedTable = new javax.swing.JTable();
        jSeparator4 = new javax.swing.JSeparator();
        btnReload = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lblFilename = new javax.swing.JLabel();
        lblStatus = new javax.swing.JLabel();
        myProgressBar = new javax.swing.JProgressBar();
        btnVerify = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        txtChatArea = new javax.swing.JTextArea();
        jSeparator5 = new javax.swing.JSeparator();
        jLabel5 = new javax.swing.JLabel();
        txtMessage = new javax.swing.JTextField();
        btnSendMessage = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        ListOfPeers = new javax.swing.JList();
        jSeparator6 = new javax.swing.JSeparator();
        btnFindPeers = new javax.swing.JButton();
        btnStopPeerSearch = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        MenuItemConnect = new javax.swing.JMenuItem();
        MenuItemDisconnect = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        MenuItemExit = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenu4 = new javax.swing.JMenu();
        ItemWindowStyle = new javax.swing.JMenuItem();
        ItemSwingStyle = new javax.swing.JMenuItem();
        ItemOthersStyle = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        ItemAboutMe = new javax.swing.JMenuItem();

        AboutMe.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        AboutMe.setTitle("About Me");
        AboutMe.setLocationByPlatform(true);
        AboutMe.setMinimumSize(new java.awt.Dimension(540, 430));
        AboutMe.setModal(true);
        AboutMe.getAccessibleContext().setAccessibleParent(this);
        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/24x24/MMU.png")));
        jLabel7.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel8.setFont(new java.awt.Font("Comic Sans MS", 3, 14));
        jLabel8.setForeground(new java.awt.Color(102, 0, 0));
        jLabel8.setText("Project Name:    Peer-To-Peer File Sharing Application");

        jLabel9.setFont(new java.awt.Font("Comic Sans MS", 3, 14));
        jLabel9.setForeground(new java.awt.Color(102, 0, 0));
        jLabel9.setText("Author Name:    Seyed Saeed Ghiassy");

        jLabel10.setFont(new java.awt.Font("Comic Sans MS", 3, 14));
        jLabel10.setForeground(new java.awt.Color(102, 0, 0));
        jLabel10.setText("Supervisor:       Dr. Fakas");

        jTextArea1.setColumns(20);
        jTextArea1.setEditable(false);
        jTextArea1.setRows(5);
        jTextArea1.setText("Year:  2007-2008\nDescription: This application is based on JXTA technology \nby Sun Microsystems; The concept of this application is to \nsharing resources over the specified Groups in JXTA network.");
        jScrollPane6.setViewportView(jTextArea1);

        jTextArea2.setColumns(20);
        jTextArea2.setEditable(false);
        jTextArea2.setFont(new java.awt.Font("Monospaced", 1, 13));
        jTextArea2.setForeground(new java.awt.Color(252, 0, 51));
        jTextArea2.setRows(5);
        jTextArea2.setText("!!!! WARNING !!!! \nThis application is for educational purposes only, And \nThe Author has No responsibility over the Resources \nthat might be Shared in this Network. \n");
        jTextArea2.setBorder(javax.swing.BorderFactory.createTitledBorder("Terms and Conditions"));
        jScrollPane7.setViewportView(jTextArea2);

        btnAccept.setText("Accept");
        btnAccept.setToolTipText("Accept terms and conditions");
        btnAccept.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAcceptActionPerformed(evt);
            }
        });

        btnExit.setText("Exit");
        btnExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExitActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 413, Short.MAX_VALUE)
                            .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 413, Short.MAX_VALUE)
                            .addComponent(jLabel10)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator7, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(btnExit, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)
                        .addGap(366, 366, 366)
                        .addComponent(btnAccept, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
                            .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel10))
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator7, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnExit)
                    .addComponent(btnAccept))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout AboutMeLayout = new javax.swing.GroupLayout(AboutMe.getContentPane());
        AboutMe.getContentPane().setLayout(AboutMeLayout);
        AboutMeLayout.setHorizontalGroup(
            AboutMeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AboutMeLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        AboutMeLayout.setVerticalGroup(
            AboutMeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AboutMeLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(43, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SaEeD P2P File Sharing Application V0.01");
        setLocationByPlatform(true);
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Connection Information:"));
        txtLog.setColumns(20);
        txtLog.setEditable(false);
        txtLog.setRows(5);
        txtLog.setText("===== Welcome to SaEeD's Peer-To-Peer File Sharing Application =====\n");
        txtLog.setToolTipText("Connection Information");
        txtLog.setBorder(javax.swing.BorderFactory.createTitledBorder("Log:"));
        jScrollPane1.setViewportView(txtLog);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 748, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 473, Short.MAX_VALUE)
                .addContainerGap())
        );
        jTabbedPane1.addTab("Connection Log", new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/24x24/LogIcon.png")), jPanel1, "Connection Information");

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Search for Files:"));
        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel1.setText("File Name:");

        txtFilename.setToolTipText("Enter File Name to search for.");

        mySearchTable.setAutoCreateRowSorter(true);
        mySearchTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "File Name", "Size Bytes", "Check Sum (CRC-32)"
            }
        ));
        mySearchTable.setToolTipText("List of Found Files.");
        jScrollPane2.setViewportView(mySearchTable);

        btnSearch.setIcon(new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/24x24/searchIcon.png")));
        btnSearch.setText("Search");
        btnSearch.setToolTipText("Start Searching");
        btnSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchActionPerformed(evt);
            }
        });

        btnStop.setIcon(new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/24x24/cancelIcon.png")));
        btnStop.setText("Stop");
        btnStop.setToolTipText("Stop searching progress");
        btnStop.setEnabled(false);
        btnStop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStopActionPerformed(evt);
            }
        });

        btnDownload.setIcon(new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/24x24/saveIcon.png")));
        btnDownload.setText("Download");
        btnDownload.setToolTipText("Downloading Selected File.");
        btnDownload.setEnabled(false);
        btnDownload.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDownloadActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 748, Short.MAX_VALUE)
                    .addComponent(jSeparator3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 748, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtFilename, javax.swing.GroupLayout.PREFERRED_SIZE, 356, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btnSearch)
                        .addGap(4, 4, 4)
                        .addComponent(btnDownload, javax.swing.GroupLayout.PREFERRED_SIZE, 525, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnStop, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtFilename, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 313, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnDownload)
                    .addComponent(btnSearch)
                    .addComponent(btnStop))
                .addContainerGap(64, Short.MAX_VALUE))
        );
        jTabbedPane1.addTab("Search", new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/24x24/searchIcon2.png")), jPanel2, "Search for Shared Files.");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("List of Shared Files:"));
        mySharedTable.setAutoCreateRowSorter(true);
        mySharedTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Type", "File Name", "Size Bytes", "Check Sum (CRC-32)"
            }
        ));
        mySharedTable.setToolTipText("My Shared Files");
        jScrollPane3.setViewportView(mySharedTable);

        btnReload.setIcon(new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/24x24/reloadIcon.png")));
        btnReload.setMnemonic('R');
        btnReload.setText("Reload");
        btnReload.setToolTipText("Refreshing Shared Files.");
        btnReload.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReloadActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 748, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jSeparator4, javax.swing.GroupLayout.DEFAULT_SIZE, 768, Short.MAX_VALUE)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnReload, javax.swing.GroupLayout.DEFAULT_SIZE, 748, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 382, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnReload)
                .addContainerGap(47, Short.MAX_VALUE))
        );
        jTabbedPane1.addTab("Shared Files", new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/24x24/folderIcon.png")), jPanel3, "List of Shared Files");

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Download Status:"));
        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel2.setText("File Name:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel3.setText("Status:");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel4.setText("Complited:");

        lblFilename.setFont(new java.awt.Font("Tahoma", 1, 12));
        lblFilename.setForeground(new java.awt.Color(153, 0, 0));
        lblFilename.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblFilename.setText("None");
        lblFilename.setToolTipText("Downloading file name");
        lblFilename.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        lblStatus.setForeground(new java.awt.Color(0, 0, 153));
        lblStatus.setText("Waiting.....");
        lblStatus.setToolTipText("Status of current download");

        myProgressBar.setStringPainted(true);

        btnVerify.setIcon(new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/16x16/varifyIcon.png")));
        btnVerify.setText("Verify");
        btnVerify.setToolTipText("Verify Downloaded File");
        btnVerify.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVerifyActionPerformed(evt);
            }
        });

        btnCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/16x16/cancelIcon.png")));
        btnCancel.setText("Cancel");
        btnCancel.setToolTipText("Cancel Download");
        btnCancel.setEnabled(false);
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 65, Short.MAX_VALUE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(myProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblStatus, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                        .addComponent(lblFilename, javax.swing.GroupLayout.PREFERRED_SIZE, 313, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btnVerify, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnCancel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(281, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(lblFilename)
                    .addComponent(btnVerify))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(lblStatus))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(myProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancel))
                .addContainerGap(397, Short.MAX_VALUE))
        );
        jTabbedPane1.addTab("Downloads", new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/24x24/downloadIcon.png")), jPanel4, "Downloads Status");

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Peers Chatting Service:"));
        txtChatArea.setColumns(20);
        txtChatArea.setEditable(false);
        txtChatArea.setRows(5);
        txtChatArea.setToolTipText("Chat Area");
        jScrollPane4.setViewportView(txtChatArea);

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel5.setText("Enter Message:");

        txtMessage.setToolTipText("Enter Message Here");
        txtMessage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtMessageActionPerformed(evt);
            }
        });

        btnSendMessage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/24x24/launchIcon.png")));
        btnSendMessage.setMnemonic('S');
        btnSendMessage.setText("Send");
        btnSendMessage.setToolTipText("Sending Message");
        btnSendMessage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSendMessageActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator5, javax.swing.GroupLayout.DEFAULT_SIZE, 748, Short.MAX_VALUE)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 748, Short.MAX_VALUE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 481, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSendMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 371, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator5, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtMessage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSendMessage))
                .addContainerGap(58, Short.MAX_VALUE))
        );
        jTabbedPane1.addTab("Chat", new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/24x24/MessengerIcon.png")), jPanel5, "Peers Messenger");

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Listing Peers In Current Group"));
        ListOfPeers.setBorder(javax.swing.BorderFactory.createTitledBorder("Peers Name:"));
        ListOfPeers.setToolTipText("Peers in SaEeD Group");
        jScrollPane5.setViewportView(ListOfPeers);

        jSeparator6.setOrientation(javax.swing.SwingConstants.VERTICAL);

        btnFindPeers.setIcon(new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/24x24/searchIcon2.png")));
        btnFindPeers.setText("Find Peers");
        btnFindPeers.setToolTipText("Start Searching for Peers in SaEeD Group");
        btnFindPeers.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFindPeersActionPerformed(evt);
            }
        });

        btnStopPeerSearch.setIcon(new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/24x24/cancelIcon.png")));
        btnStopPeerSearch.setText("Stop");
        btnStopPeerSearch.setToolTipText("Stop Searching for Peers");
        btnStopPeerSearch.setEnabled(false);
        btnStopPeerSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStopPeerSearchActionPerformed(evt);
            }
        });

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/24x24/progress_bar.gif")));

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 748, Short.MAX_VALUE)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator6, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(btnStopPeerSearch, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnFindPeers, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator6, javax.swing.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(btnFindPeers)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 356, Short.MAX_VALUE)
                        .addComponent(btnStopPeerSearch)))
                .addGap(26, 26, 26)
                .addComponent(jLabel6)
                .addContainerGap())
        );
        jTabbedPane1.addTab("List Of Peers", new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/24x24/sysinfoIcon.png")), jPanel6, "Listing Peers in Group");

        jMenu1.setMnemonic('F');
        jMenu1.setText("File");
        MenuItemConnect.setIcon(new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/16x16/connectIcon.png")));
        MenuItemConnect.setMnemonic('C');
        MenuItemConnect.setText("Connect");
        MenuItemConnect.setEnabled(false);
        MenuItemConnect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuItemConnectActionPerformed(evt);
            }
        });

        jMenu1.add(MenuItemConnect);

        MenuItemDisconnect.setIcon(new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/16x16/disconnectIcon.png")));
        MenuItemDisconnect.setText("Disconnect");
        MenuItemDisconnect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuItemDisconnectActionPerformed(evt);
            }
        });

        jMenu1.add(MenuItemDisconnect);

        jMenu1.add(jSeparator1);

        MenuItemExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/16x16/exitIcon.png")));
        MenuItemExit.setMnemonic('X');
        MenuItemExit.setText("Exit");
        MenuItemExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuItemExitActionPerformed(evt);
            }
        });

        jMenu1.add(MenuItemExit);

        jMenuBar1.add(jMenu1);

        jMenu2.setMnemonic('V');
        jMenu2.setText("View");
        jMenu4.setText("Window Style");
        ItemWindowStyle.setText("Windows Look");
        ItemWindowStyle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ItemWindowStyleActionPerformed(evt);
            }
        });

        jMenu4.add(ItemWindowStyle);

        ItemSwingStyle.setText("Swing Look");
        ItemSwingStyle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ItemSwingStyleActionPerformed(evt);
            }
        });

        jMenu4.add(ItemSwingStyle);

        ItemOthersStyle.setText("Others Look");
        ItemOthersStyle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ItemOthersStyleActionPerformed(evt);
            }
        });

        jMenu4.add(ItemOthersStyle);

        jMenu2.add(jMenu4);

        jMenuBar1.add(jMenu2);

        jMenu3.setMnemonic('H');
        jMenu3.setText("Help");
        ItemAboutMe.setIcon(new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/16x16/helpIcon.png")));
        ItemAboutMe.setMnemonic('A');
        ItemAboutMe.setText("About Me");
        ItemAboutMe.setToolTipText("About Me!");
        ItemAboutMe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ItemAboutMeActionPerformed(evt);
            }
        });

        jMenu3.add(ItemAboutMe);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 785, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 545, Short.MAX_VALUE)
                .addContainerGap())
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void MenuItemConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuItemConnectActionPerformed
// initializing all needed obejcts and reconnect to JXTA network
        MenuItemConnect.setEnabled(false);
       
        //Starting Chat Services, which includes chat input and Output using the same pipe.
        chatIn = new ChatInput(connection.getSaEeDGroup(), this.txtLog, this.txtChatArea);
        chatIn.startListening();
        chatOut = new ChatOutput(connection.getSaEeDGroup(), this.txtLog, this.txtChatArea);
        chatOut.start();
        
        //initializing the PeersListing class to be able to find peers in SaEeDGroup
        peersList = new PeersListing(connection.getSaEeDGroup(), this.txtLog, this.ListOfPeers);
        
        //Start Sharing Services
        File myPath = new File(Path);
        launchSharing = new SaEeDSharing(connection.getSaEeDGroup(), this.txtLog, myPath);
        //Starting the Sharing Thread
        launchSharing.start();
        
    }//GEN-LAST:event_MenuItemConnectActionPerformed

    private void MenuItemDisconnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuItemDisconnectActionPerformed
// finalizing all Objects
        
        MenuItemConnect.setEnabled(true);
        launchSharing.stopCMS();
        launchSharing = null;
        chatIn.stopListening();
        chatIn = null;
        chatOut = null;
        peersList = null;
        
    }//GEN-LAST:event_MenuItemDisconnectActionPerformed

    private void btnReloadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReloadActionPerformed
    //Listing the Files in Shared Directory
         File dir = new File(Path);
         File [] listOfFiles = dir.listFiles();
         String [] titles = {"Type" , "File Name" , "Size Bytes", "Check Sum (CRC-32)"};
         int NumOfFiles =0;
         for(int i=0;i < listOfFiles.length;i++){
             if(listOfFiles[i].isFile()){
                 NumOfFiles++;
             }
         }
         
         DefaultTableModel TableModel1 = new DefaultTableModel(titles,NumOfFiles){
             public boolean isCellEditable(int rowIndex, int mColIndex) {
                return false;
            }
         };
         mySharedTable.setModel(TableModel1);
         
        //This table render is used to show file type icons in Table 
        TableCellRenderer iconHeaderRenderer = new DefaultTableCellRenderer() {
        public Component getTableCellRendererComponent(JTable table, Object value,
                boolean isSelected, boolean hasFocus, int row, int column) {
            // Inherit the colors and font from the header component
            if (table != null) {
                JTableHeader header = table.getTableHeader();
                if (header != null) {
                    setForeground(header.getForeground());
                    setBackground(header.getBackground());
                    setFont(header.getFont());
                }
            }    
            if (value !=null) {
                setIcon((ImageIcon)value);
            } else {
                setText((value == null) ? "" : value.toString());
                setIcon(null);
            }
            setBorder(UIManager.getBorder("TableHeader.cellBorder"));
            setHorizontalAlignment(JLabel.CENTER);
            return this;
        }
    };
         
         //Setting new Table render to our table
         mySharedTable.getColumnModel().getColumn(0).setCellRenderer(iconHeaderRenderer);
         
         int j=0;
         for(int i=0; i< listOfFiles.length;i++){ //Showing different icons for different file type
             if(listOfFiles[i].isFile())
             {
                 if(listOfFiles[i].getName().endsWith(".mp3") || listOfFiles[i].getName().endsWith(".MP3"))
                 {
                     mySharedTable.setValueAt(mp3Icon,j,0);                    
                     
                 }else if(listOfFiles[i].getName().endsWith(".avi") || listOfFiles[i].getName().endsWith(".mpg") ||
                         listOfFiles[i].getName().endsWith(".mpeg") || listOfFiles[i].getName().endsWith(".wmv"))
                 {
                     mySharedTable.setValueAt(VideoIcon,j,0);
                 }else{
                     mySharedTable.setValueAt(OthersIcon,j,0);
                 }
                 mySharedTable.setValueAt(listOfFiles[i].getName(),j,1);
                 mySharedTable.setValueAt(listOfFiles[i].length(),j,2);
                 mySharedTable.setValueAt(myCheckSum.getFileSum(listOfFiles[i]),j,3);
                 j++;
             }
         }
         
    }//GEN-LAST:event_btnReloadActionPerformed

    private void btnVerifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVerifyActionPerformed
    //Create Check sum for downloaded file and check it with original check sum
    // to make sure download was successfull.
        if(download.myDonwloader.isDone())
        {
            File myNewFile = new File(Path + File.separator + myFileName);
            String newSum = myCheckSum.getFileSum(myNewFile);
            if(newSum.equals(OriginalCheckSum)){
             lblStatus.setText("File Verification passed. Download was Successfull.");             
            }else{
                lblStatus.setText("File Verification NOT passed-- Download corrupted.");
                 JOptionPane.showMessageDialog(null,"CheckSum verification NOT passed.\nDownload Corrupted.","Failure",
                                               JOptionPane.ERROR_MESSAGE);
            }            
            
        }else{
           JOptionPane.showMessageDialog(null,"Download is not finished yet.\nPlease be patient...","Error",
                    JOptionPane.ERROR_MESSAGE); 
        }
    }//GEN-LAST:event_btnVerifyActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
//Canceling the current Download
        download.myDonwloader.cancel();
        lblStatus.setText("Download Canceled.");
        myProgressBar.setValue(0);
        btnCancel.setEnabled(false);
    }//GEN-LAST:event_btnCancelActionPerformed

    private void btnDownloadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadActionPerformed
//Start Downloading the Files
        int rowNum;
        if ((rowNum = mySearchTable.getSelectedRow()) != -1)
        {
            if(contentAdv != null)
            {
                OriginalCheckSum = mySearchTable.getValueAt(rowNum,2).toString();
                myFileName = mySearchTable.getValueAt(rowNum,0).toString();
                lblFilename.setText(myFileName);
                lblStatus.setText("Downloading.....");
                //initializing the file
                File saveTo = new File(Path + File.separator + myFileName);
                //starting Download
                download = new DownloadFile(connection.getSaEeDGroup(), contentAdv[rowNum],
                                            saveTo, this.txtLog, this.myProgressBar);
                download.start();
                btnCancel.setEnabled(true);
            }
            
        }else{
            JOptionPane.showMessageDialog(null,"Please select Row first then Press Download!","Error",
                    JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_btnDownloadActionPerformed

    private void btnStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStopActionPerformed
//Stoping the Search for content progress and reinitialize the Search class for furthure useage
        startSearch.killThread();
        //obtaining the ContentAdvertisements 
        contentAdv = startSearch.reqestor.searchResult;
        startSearch = null;
        btnSearch.setEnabled(true);
        btnDownload.setEnabled(true);
        btnStop.setEnabled(false);
    }//GEN-LAST:event_btnStopActionPerformed

    private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed
//Start Searching for contents in Peer Group
        startSearch = new SearchFile(connection.getSaEeDGroup(), this.txtFilename.getText(), this.txtLog,
                                     this.mySearchTable);
        startSearch.start();
        btnSearch.setEnabled(false);
        btnStop.setEnabled(true);
        btnDownload.setEnabled(false);
    }//GEN-LAST:event_btnSearchActionPerformed

    private void btnStopPeerSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStopPeerSearchActionPerformed
        //Ending Peer Search Thread
        //We need to initialize the PeersListing class again because we ended its  thread
        btnFindPeers.setEnabled(true);
        peersList.setEndOfSearch(true);
        peersList = new PeersListing(connection.getSaEeDGroup(), this.txtLog, this.ListOfPeers);
        btnStopPeerSearch.setEnabled(false);
        
    }//GEN-LAST:event_btnStopPeerSearchActionPerformed

    private void btnFindPeersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFindPeersActionPerformed
    //Start finding peers in SaEeD's Group
        peersList.start();
        btnFindPeers.setEnabled(false);
        btnStopPeerSearch.setEnabled(true);
    }//GEN-LAST:event_btnFindPeersActionPerformed

    private void txtMessageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtMessageActionPerformed
    btnSendMessageActionPerformed(evt);
    }//GEN-LAST:event_txtMessageActionPerformed

    private void btnSendMessageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSendMessageActionPerformed
    //Sending Chat message through the pipe 
    //Because we using the same pipe for input and output first we need to stop input pipe
    // then send our message then again activate our input pipe
        chatIn.stopListening();
        chatOut.setMessage(txtMessage.getText());
        chatOut.startingPipe();
        //activating the Input pipe again
        chatIn.startListening();
        txtMessage.setText("");
    }//GEN-LAST:event_btnSendMessageActionPerformed

    private void MenuItemExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuItemExitActionPerformed
        //Exiting 
        System.out.println("[+]Bye bye.");
        System.exit(0);
    }//GEN-LAST:event_MenuItemExitActionPerformed

    private void ItemOthersStyleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ItemOthersStyleActionPerformed
        //Changing to Other Style Frame
        try{
            UIManager.setLookAndFeel ("com.sun.java.swing.plaf.motif.MotifLookAndFeel") ;
            SwingUtilities.updateComponentTreeUI(this); //=====> Repaint the whole Frame !!!!!!!        
          } catch (Exception e) {
            System.err.println("Unable to change");
          }
    }//GEN-LAST:event_ItemOthersStyleActionPerformed

    private void ItemSwingStyleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ItemSwingStyleActionPerformed
        //Changing to Swing Default Frame Style
        try {
            UIManager.setLookAndFeel(new MetalLookAndFeel());
            SwingUtilities.updateComponentTreeUI(this); //=====> Repaint the whole Frame !!!!!!!!!        
      } catch (Exception e) {
        System.err.println("Unable to change");
      }
    }//GEN-LAST:event_ItemSwingStyleActionPerformed

    private void ItemWindowStyleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ItemWindowStyleActionPerformed
        //changing to Windows Style Fram
        try {        
             UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
            SwingUtilities.updateComponentTreeUI(this); //=====> Repaint the whole Frame !!!!!!!        
      } catch (Exception e) {
        System.err.println("Unable to change");
      }
    }//GEN-LAST:event_ItemWindowStyleActionPerformed

    private void ItemAboutMeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ItemAboutMeActionPerformed
        //Showing the AboutMe Dialog box.
        this.AboutMe.setVisible(true); 
    }//GEN-LAST:event_ItemAboutMeActionPerformed

    private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitActionPerformed
//Make sure that user will accept Terms and Conditions
        System.out.println("[-]Terms And Conditions did NOT accepted!\nExiting...");
        System.exit(0);
    }//GEN-LAST:event_btnExitActionPerformed

    private void btnAcceptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAcceptActionPerformed
//Make sure that user will accept Terms and Conditions
        this.AboutMe.setVisible(false);
    }//GEN-LAST:event_btnAcceptActionPerformed
    
    //Executing the Main code and initialising the Objects used in out program
    public static void main(String args[]) 
    {
        frmMain myapp = new frmMain();
        myapp.setVisible(true);
        myapp.AboutMe.setVisible(true);
        //first make sure that Terms and Conditions are Accepted by User
        FirstTimeCheck checkFirstTime = new FirstTimeCheck(myapp.txtLog);
        //Search for Configuration file, it not found assumes that it is the first time
        //that we are using this Application
        if(checkFirstTime.isFirstTime()){
            JOptionPane.showMessageDialog(null,"Please Select Folder to Share","First Time Configuration",
                                          JOptionPane.INFORMATION_MESSAGE);
            checkFirstTime.searchForConfigFile();
            Path = checkFirstTime.getSharedPath();
        }else{
            checkFirstTime.searchForConfigFile();
            Path = checkFirstTime.getSharedPath();           
        }
        //Launching JXTA 
        connection = new StartJXTA(myapp.txtLog);
        //Starting Chat Services, which includes chat input and Output using the same pipe.
        chatIn = new ChatInput(connection.getSaEeDGroup(), myapp.txtLog, myapp.txtChatArea);
        chatIn.startListening();
        chatOut = new ChatOutput(connection.getSaEeDGroup(), myapp.txtLog, myapp.txtChatArea);
        chatOut.start();
        
        //initializing the PeersListing class to be able to find peers in SaEeDGroup
        peersList = new PeersListing(connection.getSaEeDGroup(), myapp.txtLog, myapp.ListOfPeers);
        
        //Start Sharing Services
        File myPath = new File(Path);
        launchSharing = new SaEeDSharing(connection.getSaEeDGroup(), myapp.txtLog, myPath);
        //Starting the Sharing Thread
        launchSharing.start();        
        
        
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDialog AboutMe;
    private javax.swing.JMenuItem ItemAboutMe;
    private javax.swing.JMenuItem ItemOthersStyle;
    private javax.swing.JMenuItem ItemSwingStyle;
    private javax.swing.JMenuItem ItemWindowStyle;
    public javax.swing.JList ListOfPeers;
    private javax.swing.JMenuItem MenuItemConnect;
    private javax.swing.JMenuItem MenuItemDisconnect;
    private javax.swing.JMenuItem MenuItemExit;
    private javax.swing.JButton btnAccept;
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnDownload;
    private javax.swing.JButton btnExit;
    private javax.swing.JButton btnFindPeers;
    private javax.swing.JButton btnReload;
    private javax.swing.JButton btnSearch;
    private javax.swing.JButton btnSendMessage;
    private javax.swing.JButton btnStop;
    private javax.swing.JButton btnStopPeerSearch;
    private javax.swing.JButton btnVerify;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JLabel lblFilename;
    private javax.swing.JLabel lblStatus;
    public javax.swing.JProgressBar myProgressBar;
    public javax.swing.JTable mySearchTable;
    private javax.swing.JTable mySharedTable;
    public javax.swing.JTextArea txtChatArea;
    private javax.swing.JTextField txtFilename;
    public javax.swing.JTextArea txtLog;
    private javax.swing.JTextField txtMessage;
    // End of variables declaration//GEN-END:variables
    
}
